Skip to content

Add loop and restBuffer types - #170

Draft
extremeheat wants to merge 2 commits into
ProtoDef-io:masterfrom
extremeheat:newtypes
Draft

extremeheat wants to merge 2 commits into
ProtoDef-io:masterfrom
extremeheat:newtypes

Conversation

@extremeheat

Copy link
Copy Markdown
Contributor

Generated by Claude 4

loop

Reads a sequence of elements until a terminator or end of buffer:

// Read numbers until encountering 0
['loop', { type: 'i8', nt: 0 }]  // [1, 2, 3] from buffer [1, 2, 3, 0, ...]

// Read until end of buffer  
['loop', { type: 'i16', nt: null }]  // Read all remaining i16 values

restBuffer

Captures all remaining bytes as a Buffer:

// Protocol with header and payload
['container', [
  { name: 'header', type: 'u8' },
  { name: 'payload', type: 'restBuffer' }  // All remaining bytes
]]

After #169 , ProtoDef-io/ProtoDef#55

@rom1504 rom1504 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra agent review — AI-generated, not manually written by the maintainer.

Keep this draft until the loop's EOF, truncation and progress contract is consistent across engines. In particular, an incomplete i16 tail is swallowed by the interpreter but rejected by the compiler, and a zero-size element never advances the loop. The schema/submodule/validator wiring must also work without asking ordinary users to disable validation.

Coordinate those semantics with ProtoDef #55 and add malformed-tail and zero-progress controls alongside the valid fixtures. This is static read/write/size review, not a fresh full suite.

Skills used: prismarine-review checked the current revision and feedback; prismarine-protocol-data-review checked codec/schema semantics; prismarine-architecture-review checked the corresponding consumer API.

Comment thread src/datatypes/extras.js
results.push(entry.value)
offset += entry.size
} catch (error) {
if (error instanceof PartialReadError) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra agent review — AI-generated, not manually written by the maintainer.

For ["loop", {type: "i16", nt: null}] with one trailing byte, this treats the partial element as successful end-of-input; the compiled reader propagates its error. A caller therefore gets different acceptance and consumed lengths from the two engines. Choose and enforce one truncation contract, and reject zero-size element progress in both implementations to prevent a nonterminating loop on nonempty input.

Skills used: prismarine-review checked the current revision and feedback; prismarine-protocol-data-review checked codec/schema semantics; prismarine-architecture-review checked the corresponding consumer API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants